<!-- 登录 -->
<template>
  <div class="login">
    <el-container>
      <el-header height="114px"> {{title}} </el-header>
      <el-main>
        <img src="@/assets/images/login-bgk.png" class="bgk" />
        <div class="login-box">
          <ul class="title">
            <li>快速登录</li>
            <li>欢迎来到音乐在线阅卷</li>
          </ul>
          <el-form :label-position="labelPosition" :model="formLabelAlign">
            <el-form-item label="账号">
              <img src="@/assets/images/login.png" class="icons" />
              <el-input
                v-model="formLabelAlign.account"
                placeholder="请输入账号"
                :style="{ borderColor: index == 1 ? 'red' : '' }"
                @focus="index = 1"
                @blur="index = 0"
              ></el-input>
            </el-form-item>

            <el-form-item label="密码">
              <img src="@/assets/images/password.png" class="icons" />
              <el-input
                v-model="formLabelAlign.password"
                placeholder="请输入密码"
                type="password"
                :style="{ borderColor: index == 2 ? 'red' : '' }"
                @focus="index = 2"
                @blur="index = 0"
              ></el-input>
            </el-form-item>

            <el-form-item label="授权码">
              <img src="@/assets/images/authorization.png" class="icons" />
              <el-input
                v-model="formLabelAlign.authorization"
                placeholder="请输入授权码"
                :style="{ borderColor: index == 3 ? 'red' : '' }"
                @focus="index = 3"
                @blur="index = 0"
              ></el-input>
            </el-form-item>
            <div class="flex">
              <el-button round class="btn" type="danger" @click="login"
                >登录</el-button
              >
              <el-button
                round
                class="btn"
                type="danger"
                @click="$router.replace('/home')"
                >返回</el-button
              >
            </div>
          </el-form>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import { examLogin,PositionContent } from "@/api/apiData";
import { mapMutations } from "vuex";
export default {
  components: {},
  data() {
    return {
      index: 0,
      labelPosition: "top",
      formLabelAlign: {
        account: "",
        password: "",
        authorization: "",
      },
      title:''
    };
  },
  computed: {},
  methods: {
    ...mapMutations(["setToken"]),
    login() {
      const that = this;
      const { formLabelAlign } = that;
      try {
        for (let i in formLabelAlign) {
          if (formLabelAlign[i].replace(/[, ]/g, "") == "") {
            throw new Error(i);
          }
        }
      } catch (e) {
        let message;
        switch (e.message) {
          case "account":
            message = "请输入登录账号";
            break;
          case "password":
            message = "请输入登录密码";
            break;
          case "authorization":
            message = "请输入登录授权码";
            break;
        }
        this.$message({
          type: "warning",
          message: message,
        });
        return;
      }
      let obj = {
        username: formLabelAlign.account,
        password: formLabelAlign.password,
        auth_code: formLabelAlign.authorization,
      };
      examLogin(obj, false).then((res) => {
        if (res.code == 1) {
          that.setToken([
            res.data.examiner_token,
            formLabelAlign.authorization,
          ]);

          that.$router.replace("/videoResult");
        } else {
          this.$message({
            type: "error",
            message: res.msg,
          });
        }
      });
    },
  },
  created() {},
  mounted() {
    PositionContent({posid:18}).then(res=>{
       this.title = res.data.title
       document.title = res.data.title
    })
  },
};
</script>
<style lang='less' scoped>
.el-header {
  background: @main-color;
  text-align: center;
  color: #fff;
  font-size: 40px;
  line-height: 114px;
}
.bgk {
  position: fixed;
  width: 100%;
  height: 100%;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
}
.login-box {
  position: absolute;
  top: 18vh;
  width: 50%;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  border-radius: 38px;
  padding: 1% 5% 2%;
  .title {
    font-size: 35px;
    color: @main-color;
    margin-bottom: 5%;
    font-weight: bold;
    line-height: 1.5;
  }
  .icons {
    width: 42px;
    height: 42px;
    align-self: start;
  }
  /deep/.el-form-item {
    position: relative;
    margin-bottom: 50px;
  }
  /deep/.el-form-item__label {
    font-size: 25px;
    color: #373737;
    position: absolute;
    left: 70px;
    top: -1px;
    font-weight: bold;
  }
  .el-input {
    border-bottom: 1px solid #000;
    margin-top: 20px;
  }
  /deep/.el-input__inner {
    border: 0;
    border-radius: 0;
    padding: 0;
    font-size: 25px;
  }
  /deep/.btn {
    display: block;
    background: linear-gradient(to right, #ff8375, #d74939);
    width: 40%;
    margin: 0 auto;
    height: 60px;
    border-radius: 50px;
    font-size: 30px;
    margin-top: 70px;
  }
}
</style>